package com.newway.back.util;

import com.newway.back.entity.SysUserEntity;
import com.newway.back.security.MyUserDetails;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.List;

public class SecurityUserContext {


    public static SysUserEntity getCurrentUserInfo(){
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if(principal!=null){
            MyUserDetails userDetails = (MyUserDetails) principal;
            return  userDetails.getSysUserEntity();
        }
        return null;
    }

    public static List<String> getCurrentUserRoles(){
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if(principal!=null){
            MyUserDetails userDetails = (MyUserDetails) principal;
            return  userDetails.getRoles();
        }
        return null;
    }

    public static List<String> getCurrentUserPerms(){
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if(principal!=null){
            MyUserDetails userDetails = (MyUserDetails) principal;
            return  userDetails.getPerms();
        }
        return null;
    }
}
